<template>
  <div class="user-avator-dropdown">
    <Dropdown @on-click="handleClick">
      <Avatar :src="userAvatar"/>
      <span style="font-size: 12px;margin-left: 5px">{{ userName }}</span>
      <Icon :size="18" type="md-arrow-dropdown"/>
      <DropdownMenu slot="list">
        <DropdownItem name="info">个人中心</DropdownItem>
        <DropdownItem name="logout">退出登录</DropdownItem>
      </DropdownMenu>
    </Dropdown>
  </div>
</template>

<script>
  import './user.less'
  import { mapActions } from 'vuex'

  export default {
    name: 'User',
    props: {
      userAvatar: {
        type: String,
        default: ''
      },
      userName: {
        type: String,
        default: 'Admin'
      }
    },
    methods: {
      ...mapActions([
        'handleLogOut'
      ]),
      handleClick (name) {
        switch (name) {
          case 'logout':
            this.handleLogOut().then(() => {
              this.$router.push({
                name: 'login'
              })
            })
            break
          case 'info':
            this.$router.push({
              name: 'info'
            })
            break
        }
      }
    }
  }
</script>
